<?php

namespace app\common\model;

use app\common\enum\order\PayType;
use think\model\relation\HasMany;
use think\model\relation\HasOne;

class AccountRecord extends BaseModel
{
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 1=业务员，2=司机，3=经销商
    const SALESMAN = 1;
    const DRIVER = 2;
    const DEALER = 3;
    public function driver(): HasOne
    {
        return $this->hasOne(Driver::class, 'id', 'payee_id');
    }

    public function salesman(): HasOne
    {
        return $this->hasOne(Salesman::class, 'id', 'payee_id');
    }

    public function detail(): HasMany
    {
        return $this->hasMany(ReceiveLog::class, 'account_record_id', 'id');
    }

    public function refund(): HasMany
    {
        return $this->hasMany(Refund::class, 'account_record_id', 'id');
    }

    public function dealer(): HasOne
    {
        return $this->hasOne(Dealer::class, 'id', 'payee_id');
    }

    public function fz(): HasMany
    {
        return $this->hasMany(DealerCharge::class, 'account_record_id', 'id');
    }

    public function getPayTypeTextAttr($value,$data): string
    {
        $status = [PayType::CASH=>'现金',PayType::BANK=>'公司账户'];
        return $status[$data['pay_type']] ?? '无';
    }
}